package ch03.Shili.dao;

import org.apache.log4j.Logger;

import java.lang.reflect.Proxy;

public class IntermediaryJdkProxyFactory {

    private Logger logger = Logger.getLogger(IntermediaryJdkProxyFactory.class);

    public static <T> T CREATE(Object target){
        IntermediaryInvocationHandler handler = new IntermediaryInvocationHandler();
        handler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(), (java.lang.reflect.InvocationHandler) handler);
    }

    public void test(){
        Buyer buyer = IntermediaryJdkProxyFactory.CREATE(new RealBuyer());
        String result = buyer.havealook();
        logger.debug(result);
    }
}
